<%@ page import="java.util.List" %>
<%@ page import="com.lagou.module01.bean.Student" %><%--
  Created by IntelliJ IDEA.
  User: xyk
  Date: 2021/3/15
  Time: 22:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <!-- Bootstrap -->
    <link href="${pageContext.request.contextPath}/static/css/bootstrap.min.css" rel="stylesheet" media="screen">
    <script src="static/js/operation.js"></script>
    <title>学员管理系统</title>
</head>

<script>
    // 接收第一页学员信息列表，初始化
    <%
        List<Student> studentsList = (List<Student>) session.getAttribute("studentsList");
        int totalPages = (int) session.getAttribute("totalPages");
        int i = 0;
        for (Student student: studentsList){
            if (student != null){
    %>
            users[<%=i%>] = new user("<%=student.getId()%>", "<%=student.getName()%>","<%=student.getSex()%>","<%=student.getBirthday()%>","<%=student.getEmail()%>","<%=student.getRemark()%>");
            <%
            i++;}
            %>
    <%
            }
    %>

</script>

<body onload="refresh(users)">

<div class="container">
    <table class="table" id="table">
        <!-- <caption> 关于表格存储内容的描述或总结。 -->
        <caption>
            <h2>学员管理界面</h2>
        </caption>
        <caption>
            <button class="btn btn-info" id="add" data-toggle="modal" data-target="#myModal" >新增</button>
            <button class="btn btn-info" id="delete" onclick="return del()">删除</button>
            <button class="btn btn-info" id="edit" data-toggle="modal" data-target="#myModal" onclick="return edit()">编辑</button>
            <div class="find">
                <form action="queryStudentServlet" method="post">
                    <input id="find-text" type="text" name="key" placeholder="输入学号" style="widows: 130px;">
                    <input class="find-btn" type="submit" value="查询">
                </form>
            </div>
        </caption>
        <thead>
        <tr>
            <th>序号</th>
            <th>工号</th>
            <th>姓名</th>
            <th>性别</th>
            <th>生日</th>
            <th>邮箱</th>
            <th>备注</th>
        </tr>
        </thead>
        <tbody class="tbody" id="tbody">
        </tbody>
    </table>
    <%
        int currentPage = Integer.parseInt((String) session.getAttribute("currentPage"));
    %>
    <%
        if (totalPages >= 1){
    %>
        <ul class="pagination">
            <li > <a href="pageQueryServlet?page=1"> 首页 </a> </li>
            <%
                if (currentPage > 1){
            %>
                <li class="previous"> <a href="pageQueryServlet?page=<%=currentPage-1%>"> &laquo; </a> </li>
            <%
                }
            %>
            <%
                for (int j=1; j<=totalPages; j++){
            %>
            <li> <a href="pageQueryServlet?page=<%=j%>"><%=j%></a> </li>
            <%
                }
            %>
            <%
                if (currentPage < totalPages){
            %>
                <li class="next"> <a href="pageQueryServlet?page=<%=currentPage+1%>">&raquo;</a> </li>
            <%
                }
            %>

            <li > <a href="pageQueryServlet?page=<%=totalPages%>">尾页</a> </li>
            <li style="text-align: center; vertical-align: middle; color: #2e6da4; font-size: 1.25em"> &nbsp;&nbsp;&nbsp;共<%=totalPages %>页 </li>
        </ul>
    <%
        }
    %>

    <!-- 模态框 -->
    <!-- 声明定义模态框组件 -->
    <div class="modal" id="myModal" role="dialog">
        <!-- 窗口声明 -->
        <div class="modal-dialog">
            <!-- 内容声明 -->
            <div class="modal-content">
                <!-- 1.框的标题 -->
                <!-- data-dismiss="modal" 取消的属性 -->
                <div class="modal-header">
                    <button class="close" data-dismiss="modal" aria-hidden="true">
                        <span>&times;</span>
                    </button>
                    <h4 class="modal-title">新增学生</h4>
                </div>
                <form action="addStudentServlet" method="post">
                    <!-- 2.框内信息 -->
                    <div class="modal-body">
                        <label for="id">学号:</label>
                        <input name="id" type="text" class="form-control" id="m_code" placeholder="请输入工号">
                        <label for="name">姓名:</label>
                        <input name="userName" type="text" class="form-control" id="m_userName" placeholder="请输入姓名">
                        <label for="sex">性别:</label>
                        <input name="sex" type="text" class="form-control" id="m_sex" placeholder="请输入性别">
                        <label for="birthday">生日:</label>
                        <input name="birthday" type="text" class="form-control" id="m_birthday" placeholder="请输入出生日期">
                        <label for="email">邮箱:</label>
                        <input name="email" type="text" class="form-control" id="m_email" placeholder="请输入邮箱">
                        <label for="remark">备注:</label>
                        <input name="remark" type="text" class="form-control" id="m_remark" placeholder="请输入备注">
                    </div>
                    <!-- 3.框的按钮 -->
                    <div class="modal-footer">
                        <button class="btn btn-primary" type="submit" onclick="return alert('操作成功')">提交</button>
                        <button class="btn btn-default" type="reset" data-dismiss="modal">取消</button>
                    </div>
                </form>

            </div>
        </div>
    </div>

</div>

<script src="static/js/jquery-3.3.1.min.js"></script>
<script src="static/js/bootstrap.min.js"></script>

</body>




</html>